﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace example
{
    public class Vertex
    {
        public string Name;
        public List<Edge> edges = new List<Edge>();
        public Vertex(string _name)
        {
            Name = _name;
        }
    }

    public class Edge
    {
        public Vertex start;
        public Vertex end;
        int weight;
        public Edge(Vertex _start, Vertex _end, int _peso)
        {
            start = _start;
            end = _end;
            weight = _peso;
            start.edges.Add(this);
            end.edges.Add(this);
        }
    }

    public class Graph
    {
        Dictionary<string, Vertex> V = new Dictionary<string,Vertex>();
        List<Edge> E = new List<Edge>();
        public Graph(string[][] elems, int threshold)
        {
            for (int i = 0; i < elems.Length; i++)
            {
                if (int.Parse(elems[i][2]) > threshold)
                    continue;

                var start = new Vertex(elems[i][0]);
                var end = new Vertex(elems[i][1]);
                var peso = int.Parse(elems[i][2]);
                var edge = new Edge(start, end, peso);
                start.edges.Add(edge);

                if (!V.ContainsKey(start.Name))
                {
                    V.Add(start.Name, start);
                }
                else
                {
                    V[start.Name].edges.Add(edge);
                }
                if (!V.ContainsKey(end.Name))
                {
                    V.Add(end.Name, end);
                }
                else
                {
                    V[end.Name].edges.Add(edge);
                }
                E.Add(edge);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var f = File.ReadAllLines("10kb_graph.all.txt");
            int threshold = 3;
            var edges =
                (
                    from s in f
                    let el = s.Split(new char[] { '\t' })
                    select el
                ).ToArray();
            var g = new Graph(edges, threshold);
        }
    }
}
